//
//  XJMainTabBarViewController.m
//  XinJiangMall
//
//  Created by Tzyang on 2018/4/2.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJMainTabBarViewController.h"
#import "XJTabBar.h"
#import "XJNavViewController.h"

#import "UITabBar+CustomBadge.h"
//Controller
//#import "XJYouMingTangViewController.h"

@interface XJMainTabBarViewController ()<UITabBarControllerDelegate,XJTabBarDelegate>

{
    XJTabBar *_tabBar;
}

@end

@implementation XJMainTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initSubviews];
    
    [self initTabBar];
}


- (void)initSubviews {
    NSArray *viewControllers = @[@"XJHomeViewController",@"XJGoodsViewController",@"XJYouMingTangViewController",@"XJShopCartViewController",@"XJMeViewController"];
//    NSArray *viewControllers = @[@"XJHomeViewController",@"XJGoodsViewController",@"XJYouMingTangViewController",@"JVShopcartViewController",@"XJMeViewController"];

    
    // 创建导航控制器
    NSMutableArray *baseNavs = [NSMutableArray array];
    
    for (NSInteger i = 0; i < viewControllers.count; i++) {
        Class cls = NSClassFromString(viewControllers[i]);
        if (cls) {
            UIViewController *controller = [[cls alloc] init];
            XJNavViewController *nav= [[XJNavViewController alloc] initWithRootViewController:controller];
            [baseNavs addObject:nav];
        }
    }
    self.viewControllers = baseNavs;
}

- (void)initTabBar{
    _tabBar = [[XJTabBar alloc] initWithFrame:self.tabBar.bounds];
    _tabBar.tabBarItemAttributes = @[
                                     @{kXJTabBarItemAttributeTitle : @"首页", kXJTabBarItemAttributeNormalImageName : @"tab_home_off", kXJTabBarItemAttributeSelectedImageName : @"tab_home_on", kXJTabBarItemAttributeType : @(XJTabBarItemTypeNormal)},
                                     @{kXJTabBarItemAttributeTitle : @"分类", kXJTabBarItemAttributeNormalImageName : @"tab_classification_off", kXJTabBarItemAttributeSelectedImageName : @"tab_classification_on", kXJTabBarItemAttributeType : @(XJTabBarItemTypeNormal)},
                                     @{kXJTabBarItemAttributeTitle :@"", kXJTabBarItemAttributeNormalImageName : @"tab_ymt", kXJTabBarItemAttributeSelectedImageName : @"tab_ymt", kXJTabBarItemAttributeType : @(XJTabBarItemTypeRise)},
                                     @{kXJTabBarItemAttributeTitle : @"购物车", kXJTabBarItemAttributeNormalImageName : @"tab_cart_off", kXJTabBarItemAttributeSelectedImageName : @"tab_cart_on", kXJTabBarItemAttributeType : @(XJTabBarItemTypeNormal)},
                                     @{kXJTabBarItemAttributeTitle : @"我的", kXJTabBarItemAttributeNormalImageName : @"tab_my_off", kXJTabBarItemAttributeSelectedImageName : @"tab_my_on", kXJTabBarItemAttributeType : @(XJTabBarItemTypeNormal)}];



if (!IOS10) {
    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
}
//    _tabBar.delegate = self;
    [self.tabBar addSubview:_tabBar];
    //UIImage * imag =[UIImage imageNamed:@"tab_background"];
    // self.tabBar.layer.contents=(id)imag.CGImage;
    self.tabBar.alpha=1.0;
    [self.tabBar setTabIconWidth:15];
    [self.tabBar setBadgeTop:9];
    

}

- (void)tabBarDidSelectedRiseButton{
    XJLog(@"点击");
    //    LaunchViewController *meVC=[[LaunchViewController alloc]init];
    //    [self.navigationController pushViewController:meVC animated:YES];
    //    NavigationViewController *meNav=[[NavigationViewController alloc]initWithRootViewController:meVC];
    //    [self presentViewController:meNav animated:YES completion:^{
    //
    //    }];

//    UINavigationController ;
//    UITabBarController UIViewController;
//    UIViewController;
}

- (void)removeSystemTabbarButton {
    // 遍历tabbar上面的所有子视图，移除上面的按钮
    for (UIView *view in self.tabBar.subviews) {
        Class c = NSClassFromString(@"UITabBarButton");
        if ([view isKindOfClass:[c class]]) {
            [view removeFromSuperview];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
